package com.sdkj.dspservice.common.base.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 *  基础返回类
 * @author Administrator
 */
@Data
public class BaseResult<T> {

    /**
     * 数据
     */
    protected Object data;
    /**
     * 状态码
     */
    protected int code;
    /**
     * 信息
     */
    protected String msg;
    /**
     * 错误详情
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    protected String errorMessage;

    public BaseResult() {
    }

    public BaseResult success(Object data) {
        this.data = data;
        return this;
    }

    /**
     * 操作成功
     * @param data
     * @param msg
     * @return
     */
    public void success(Object data, String msg){
        this.data = data;
        this.msg = msg;
    }

    /**
     * 操作失败
     * @param code
     */
    public void error(int code){
        this.code = code;
    }

    /**
     * 操作失败
     * @param code
     * @param errorMsg
     */
    public void error(int code, String errorMsg){
        this.code = code;
        errorMessage = errorMsg;
    }

}
